#ifndef WRAP_INET_H
#define WRAP_INET_H

#include "socket.h"

#include <cinttypes>
#include <netinet/in.h>

namespace Wrap {
/// @see https://man7.org/linux/man-pages/man3/htons.3p.html
/// @return The htonl() shall return the argument value converted from host to
/// network byte order.
uint16_t htons_(uint16_t hostshort);

/// @see https://man7.org/linux/man-pages/man3/inet_aton.3.html
/// @param cp inet_aton() converts the Internet host address @c cp from the
/// IPv4 numbers-and-dots notation into binary form (in network byte order)
/// @param inp and stores it in the structure that @c inp points to.
/// @return inet_aton() returns 1 if the supplied string was successfully
/// interpreted, or 0 if the string is invalid (errno is not set on error).
int inet_aton_(const char *cp, struct in_addr *inp);

/// @see https://man7.org/linux/man-pages/man3/inet_aton.3.html
/// @param in The inet_ntoa() function converts the Internet host address @c in,
/// given in network byte order, to a string in IPv4 dotted-decimal notation.
/// @return The string is returned in a statically allocated buffer, which
/// subsequent calls will overwrite.
char *inet_ntoa_(struct in_addr in);

/// @see https://man7.org/linux/man-pages/man3/inet_ntop.3.html
/// @param cp This function converts the network address structure @c cp
/// @param af in the @c af address family into a character string.
/// @param buf The resulting string is copied to the buffer pointed to by
/// @c buf, which must be a non- null pointer.
/// @param len The caller specifies the number of bytes available in this
/// buffer in the argument @c len.
/// @return On success, inet_ntop() returns a non-null pointer to dst. NULL is
/// returned if there was an error, with errno set to indicate the error.
/// @throw EAFNOSUPPORT @c af was not a valid address family.
/// @throw ENOSPC The converted address string would exceed the size given by @c
/// len.
const char *inet_ntop_(int af, const void *cp, char *buf, socklen_t_ len);

/// @see https://man7.org/linux/man-pages/man3/inet_pton.3.html
/// @param cp This function converts the character string @c cp
/// @param af into a network address structure in the @c af address family,
/// The @c af argument must be either AF_INET or AF_INET6.
/// @param buf then copies the network address structure to @c buf. @c buf is
/// written in network byte order.
/// @return inet_pton() returns 1 on success (network address was successfully
/// converted). 0 is returned if @c cp does not contain a character string
/// representing a valid network address in the specified address family. If
/// @c af does not contain a valid address family, -1 is returned and errno is
/// set to EAFNOSUPPORT.
/// @throw EAFNOSUPPORT @c af does not contain a valid address family
int inet_pton_(int af, const char *cp, void *buf);

}

#endif